import{
    Product,
    AbstractProductA,
    AbstractProductB,
 } from "../../public/Product"

//抽象工厂基类
interface AbstractFactory {
    createProductA(): AbstractProductA
    createProductB(): AbstractProductB
}

//具体产品1、2、3、4
class ConcreateProductA extends AbstractProductA { }
class ConcreateProductB extends AbstractProductA { }
class ConcreateProductC extends AbstractProductB { }
class ConcreateProductD extends AbstractProductB { }

//具体工厂1
class ConcreateFactoryA implements AbstractFactory {
    constructor() { }
    public createProductA(): AbstractProductA {
        return new ConcreateProductA()
    }

    public createProductB(): AbstractProductB {
        return new ConcreateProductC()
    }
}

//具体工厂2
class ConcreateFactoryB implements AbstractFactory {
    constructor() { }
    public createProductA(): AbstractProductA {
        return new ConcreateProductB()
    }
    public createProductB(): AbstractProductB {
        return new ConcreateProductD()
    }
}


//创建工厂
const factory1: AbstractFactory = new ConcreateFactoryA()
const factory2: AbstractFactory = new ConcreateFactoryB()

//创建产品
const product1 = factory1.createProductA()
const product3 = factory2.createProductA()
const product2 = factory1.createProductB()
const product4 = factory2.createProductB()

const products: Array<Product> = [product1,product2,product3,product4]

const abstractFactoryTest = ():void =>{
    console.table(products)
}

abstractFactoryTest()